<?php

include_once("user.class.php");
include_once("userMapper.class.php");

define ('SALT', '$5$jediphpavanzadoisournewsalt$');

function login() {
    if (isset($_POST["username"])) {
        $user = UserMapper::findByUsername($_POST["username"]);
        if ($user == false) return false;
        else {
            if ($user->get_password() == crypt($_POST["password"], SALT)) {
                $_SESSION["userid"] = $user->get_userid();
                $_SESSION["username"] = $user->get_username();
                $_SESSION['email'] = $user->get_mail();
                return true;
            }
        }
    }
    return false;
}

?>
